#include "XOSection.h"

#include "FKDisplayReferent.h"

#include <QColor>

#include "FKLogger.h"
#include "FKSDM.h"

FK_EVENTS(XOSection){
props.append(XOEvent::c_coord);
props.append(XOEvent::c_owner);
}

XOSection::XOSection(FKRoom* room,qint32 objectID):FKObject3D(room,objectID){
	FK_CBEGIN
	FK_CONSTRUCTOR
	FK_CEND
}

XOSection::~XOSection(){
	FK_DBEGIN
	FK_DESTRUCTOR
	FK_DEND
}

void XOSection::customInitialization(){
    installReferent();
    refreshReferent();
    c_owner(owner());
    setSize(0.31f);
}

void XOSection::customDeinitialization(){
}

void XOSection::installReferent(){
    setDisplayReferent(new FKDisplayReferent(FKSDM::quad,getID()));
    displayReferent()->show();
}

void XOSection::a_clicked(FKEvent* action){
    Q_UNUSED(action)
    if(getOwner()==NO_OWNER)emit clicked(getCoord());
}

void XOSection::setOwner(const qint8 &v){
    if(servant)servant->owner=v;
    updateProp(XOEvent::c_owner);
    QColor c;
    if(v==NO_OWNER){
        c=QColor(Qt::gray);
    }else if(v==X_OWNER){
        c=QColor(Qt::red);
    }else{
        c=QColor(Qt::blue);
    }
    setColor(QVector4D(c.red(),c.green(),c.blue(),c.alpha()));
}

void XOSection::c_owner(const qint8& v){
    if(customValues){
        customValues->owner=v;
    }
}
